%将制作GIF打包成函数，会让主代码显得更条理
function makeaGIF(pic_num)    
    drawnow;
    F=getframe(gcf);
    I=frame2im(F);
    [I,mapa]=rgb2ind(I,256);
    if pic_num == 1
        imwrite(I,mapa,'test.gif','gif', 'Loopcount',inf,'DelayTime',0.1);
    else
        imwrite(I,mapa,'test.gif','gif','WriteMode','append','DelayTime',0.1);
    end
    return 
end